package org.coast.mvc.logging;

import java.util.Objects;

/**
 * log 实现处理器
 */
public abstract class LogHandler {

    /**
     * 格式化
     */
    private LogFormatter formatter;

    /**
     * log 等级级别
     */
    private LogLevel logLevel;

    /**
     * 初始化配置信息
     */
    abstract void configure();

    abstract void publish(LogRecord logRecord);

    abstract boolean accept(String type);

    public LogFormatter getFormatter() {
        return formatter;
    }

    public void setFormatter(LogFormatter formatter) {
        this.formatter = formatter;
    }

    public LogLevel getLogLevel() {
        return logLevel;
    }

    public void setLogLevel(LogLevel logLevel) {
        this.logLevel = logLevel;
    }

    public void setLogLevel(String logLevel, LogLevel defaultLevel) {
        if (!Objects.isNull(logLevel) && logLevel.length() > 0) {
            defaultLevel = LogLevel.valueOf(logLevel);
        }
        this.logLevel = defaultLevel;
    }
}
